﻿using Oracle.ManagedDataAccess.Client;
using System;
using System.Collections.Generic;
using System.Data.Common;
using System.Linq;
using System.Text;
using UPos.Core;

namespace UPos.Core.Entity
{
    public class Sale
    {
        public string FID { get; set; }

        public DateTime BizDate { get; set; }

        public string MachineNo { get; set; }

        public string BillNumber { get; set; }

        public string CreaterNumber { get; set; }

        public string CreaterName { get; set; }

        public Decimal Amount { get; set; }

        public Decimal Paymentmoney { get; set; }

        public DateTime UpDate { get; set; }

        public List<SaleEntry> SaleItems { get; set; }

        public List<ReceiveEntries> ReceiveItems { get; set; }

        public Sale() { }

        public Sale(DbDataReader reader)
        {
            FID             = reader.GetString(reader.GetOrdinal("FID"));
            BizDate         = reader.GetDateTime(reader.GetOrdinal("BizDate"));
            MachineNo       = reader.GetString(reader.GetOrdinal("MachineNo"));
            BillNumber      = reader.GetString(reader.GetOrdinal("BillNumber"));
            CreaterNumber   = reader.GetString(reader.GetOrdinal("CreaterNumber"));
            CreaterName     = reader.GetString(reader.GetOrdinal("CreaterName"));
            Amount          = reader.GetDecimal(reader.GetOrdinal("Amount"));
            Paymentmoney    = reader.GetDecimal(reader.GetOrdinal("Paymentmoney"));
            try
            {
                UpDate = reader.GetDateTime(reader.GetOrdinal("UpDate"));
            }
            catch (Exception)
            { }
        }

        #region ORACLE_SALES
        static string ORACLE_SALES = @"
Select
a.fid FID
, a.fbizdate BizDate
, a.cfmachineno MachineNo
, a.fnumber BillNumber
, u.fnumber CreaterNumber
, u.fname_l2 CreaterName
, sum(b.cfamount) Amount
, a.cfpaymentmoney Paymentmoney
FROM CT_BIL_RetailPos A 
JOIN Ct_Bil_Retailposentry b on a.fid = b.fparentid
JOIN T_DB_WAREHOUSE C ON A.CFStorageID = C.FID
join T_PM_User u on u.fid = a.fcreatorid
where c.fnumber = 'SH001'
group by 
a.fid
, a.fbizdate 
, a.cfmachineno 
, a.fnumber 
, u.fnumber 
, u.fname_l2
, a.cfpaymentmoney";
        #endregion
    }
}
